package com.huanhuan.doc;

import org.apache.http.HttpHost;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;

public class ESTest_Client_doc_Delete_Batch {
    public static void main(String[] args) throws  Exception{
        //1.创建客户端对象
        //创建服务主机名 和 Web 通信端口
        final String hostname = "localhost";
        final int port = 9200;
        final String scheme = "http";
        HttpHost httpHost = new HttpHost( hostname, port, scheme );


        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(httpHost)
        );

        //批量插入
        BulkRequest request = new BulkRequest();
        request.add( new DeleteRequest().index("user").id("1002"));
        request.add( new DeleteRequest().index("user").id("1003"));
        request.add( new DeleteRequest().index("user").id("1004"));

        BulkResponse bulk = client.bulk( request, RequestOptions.DEFAULT );

        System.out.println( bulk.getTook() );
        System.out.println( bulk.getItems() );


        //关闭ES 资源
        client.close();
    }
}
